home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
embedded
/
ibm
/
sym_r3.arc
/
SIM_R3.DOC
< prev
next >
Wrap
Text File
|
1991-11-27
|
18KB
|
385 lines
SIM_R3.DOC
I. Introduction
A. Who wrote sim_r3 and why
B. Disclaimer
II. Using sim_r3.exe
A. Items on the display
B. Explanation of commands
III. Recompiling sim_r3
A. For the IBM-PC
1. Using Microsoft C 5.0 or higher
2. Using another compiler
B. For non-IBM compatible machines
I. Introduction
I. A. Who wrote sim_r3 and why
All files in this archive were written entirely by myself,
Joseph Schachner. I can be contacted via Compuserve
(73637,3437).
/* I, Amir Bernstein, have made several improvements and fixed
minor bugs, I can be contacted on FREEWARE BBS */
sim_r3 was written to support a project where I work which
is planning to use a 68705R3. Because the 68705 program and
data memory is compeletly internal, debugging a running 68705
is nearly impossible. Of course, the 68705 can be emulated
by hardware, at a cost of several thousand dollars. This is
an excellent debugging solution. However, simulation with
software provides a very good debugging environment for
almost no cost. sim_r3 is in use by another engineer at my
workplace, and has already found several bugs.
I. B. Disclaimer
Although I am an experienced 6800 family programmer, and I
took great care to insure the accuracy of this emulation, and
several bugs have been found and fixed as the program has
been used, I make no representation that this program in its
current form is either bug free or will precisely meet your
needs. The source code is distributed in this archive for
you to add (or change) any feature. If you change and
recompile sim_r3.exe, PLEASE do not distribute it without
noting your changes in this file!
Changes:
V1.21 - added clear of latched external interrupt to
simulated reset routine in instr.c. This change is
present in the source code in this archive. This was an
omission in 1.2 and earlier, but the only symptom is, if
you issue 'I' and then reset before simulating servicing
the interrupt the interrupt persists. 8-July-1989 Joe
Schachner
/* V2.00 - The major changes are the symbol table support (5 chars/label)
and the requirement(!) for VGA in order to support 50 line mode,
the source code can always be changed to allow for different
numbers of line per screen.
Additional changes to files are noted:
INSTR.C - Add MUL (actually implements MUL).
Add STOP, WAIT (do not actually STOP or WAIT).
Update timings for HC05 devices.
Add symbol table reference by "linked list".
INSTR2.C - Add symbol table reference to JMP, JSR, BRANCH
these do not appear as cleanly in "assignment"
column but it is clear enough.
Add STOP, WAIT (CCR modify).
Fix TAX,TXA by masking off the upper byte.
Fix ROR,ROL by masking off the upper byte.
V I SIM_MEM.C - sym_nmbr[], sym_tbl[] memory reference.
E M load_sym() is identical to load() but it is very
R P important(!!!) to specify the correct file with
Y O the symbol table since otherwise the program will
R get lost (it searches for the \f charcater the
T assembler inserts in the output listing in
A the load_sym_data() routine).
N sym_writef_init() initialized the memory "image"
T sym_writef() actually sets the "linked list".
SIM_R3.C - sym_nmbr[], sym_tbl[] memory allocation.
add 'y' condition for keyboard input.
*/
II. Using sim_r3.exe
Normally, one develops for a 6805 family processor using an
assembler and possibly a linker. The output from the
development tools is a file containing Motorola hex format
records (S0, S1 and S9).
The simulator loads in the Motorola hex file in response to
the 'L' command (see below). By default trace display and
log file capture are on. The simulator responds to your
commands input in either upper or lower case.
Note: the simulator's trace log file is named "sim_r3.log"
and is created in the current directory when the simulator
is started. If a file with the same name existed, it is
replaced by the new (empty) file.
sim_r3 is a very small program. When compiled with Microsoft
C 5.0, it is about 55,000 bytes. /* QuickC yeilds 45K */
Therefore, even 256K of memory is more than enough. If you
plan to turn on the log file (to capture the trace on disk),
it helps to have a hard disk to keep execution speed up.
II. A. Items on the display
When sim_r3 is started, it puts up the following on the top
seven lines of the display:
68705R3 Simulator V1.2 6-July-1989 Disp+log ON Halted
R - disp/chg regs L file - load Sx & reset E - toggle TIE G - Go
T - trace on/off B addr - Break at address (go) I - /INT S - Step
X - Reset M addr - Mem view/mod Z - Disassem H - Halt Q - Quit
/* Y - symbol table */
______________________________________________________________________________
The top line (line 1) shows program status. The next three
lines list commands, which will be explained below. The fifth
line is always blank. The sixth line is where all commands
appear as you type them, and where prompts and messages
appear; this line will be referred to as the "prompt line".
The next line (line 7) is a solid bar separating the fixed
top portion of the screen from the trace display, which
scrolls up from line 24 to line 8 and vanishes. Disassembly
also appears on lines 8 to 24.
The status line shows the program revision, whether trace
results will be displayed (and optionally captured to a
file), and whether simulation is in progress. The next
section, "Explanation of commands", provides more information
on these fields.
II. B. Explanation of commands
R - display / change registers
Text similar to the following appears on the prompt line:
PC= 100, A= 00, X= 00, SP= 07F, CCR=08 (I) Change?(reg) _
The user may enter (at least the first character of) the name
of any register shown, sim_r3 will prompt for a new value.
Press return without entering a register name to end this
command without changing a register. Note: the values of the
registers are displayed and entered in hex. Bits that are on
in the condition code register are also shown using the
characters HINZC.
L file - Load Sx and reset
sim_r3 reads motorola hex records. Only S1 and S9 records
are significant. Checksums are ignored. Loading is
extremely fast. When the "S9" record is encountered the load
terminates. End of file without an "S9" record causes an
error message to be displayed.
If the load completes without error, a message similar to the
following is displayed:
File test.sx loaded
When a hex file has been loaded, a simulated reset is
automatically performed (see 'X' command), below.
E - Toggle TIE in
sim_r3 simulates all four timer modes. The 'E' command
changes the state of the timer's external input. The current
state is displayed on the prompt line. The effect of
changing the state of the timer's external input depends on
the mode set by bits 4 and 5 (TIE and TIN) in the Timer
Control Register. See section 5.3 of the MC68(7)05 R/U
Series technical data book, Motorola ADI-977.
G - Go
The 'Halted' label changes to 'Running' and simulation
commences at the current PC. The breakpoint address is
unchanged. Simulation will halt when the PC equals the
breakpoint address on an opcode fetch, or if the 'H' command
is entered (see below).
T - Trace display (and logfile) on/off
If display is on when this command is entered, it is turned
off. Logfile capture is always off when display is off. If
display is off when this command is entered, the prompt
"Enable logfile also?(Y/N) " will appear. After the prompt
is answered, the label on line one will say either "Display
ON" or "Disp+Log ON". The format of the log file is
identical to that of the trace display.
Note: simulation proceeds MUCH faster if the trace display is
turned off.
An example trace display (part of a log file) appears below.
It was generated by the commands 'L test.sx', 'B 10b'.
100 A6 55 LDA #$55 101=>55 ACCUM<=55 2
102 48 LSLA ACCUM=>55 ACCUM<=AA 6
103 47 ASRA ACCUM=>AA ACCUM<=D5 10
104 97 TAX X_REG<=D5 12
105 BF 50 STX $50 050<=D5 17
107 3C 50 INC $50 050=>D5 050<=D6 23
109 26 FC BNE $107 27
107 3C 50 INC $50 050=>D6 050<=D7 33
109 26 FC BNE $107 37
^ ^ ^ ^ ^
| | | addr=>data (read) |
| | | addr<=data (write) Cycle count
| | | All values in hex. in decimal
| | Assembly Register names ACCUM,
| | Mnemonics X_REG, SP may appear.
| |
| Opcode and operand bytes for this instruction, in hex.
|
PC for opcode, in hex
The example trace continues until finally location $50
becomes zero and the BNE is not taken:
109 26 FC BNE $107 437
107 3C 50 INC $50 050=>FF 050<=00 443
109 26 FC BNE $107 447
At this point the prompt line shows "Breakpoint reached" and
the simulation is halted.
B addr - Go and break at addr
The breakpoint address is set from the address (in hex)
following the 'B'. After that, operation is the same as 'G',
above. See 'T', above, for an example of this command's
usage.
I - /INT
Latches an external interupt. If the interrupt mask is not
set sim_r3 will simulate interrupt response prior to
beginning the next simulated instruction.
S - Step
Simulate one instruction at the current PC. Similar to 'G'
except simulation is automatically halted after one
instruction. The breakpoint address is unchanged.
X - Reset
sim_r3 simulates a reset, loading the PC from the reset
vector, initializing the data direction registers and the
timer, and the timer control register from the Mask Options
Register, and setting the interrupt mask and resetting the
stack pointer to 7F, and (version 1.21 and higher) also
clears internal latched interrupt if any.
M addr - memory view/change
The address (in hex) is read as if read by a program running
in the 68705, and the address and value are displayed on the
prompt line. If 'Enter' is pressed, the next location is
displayed. If a hex value is entered, the value is written
to the displayed location and then the next location is
displayed. To get out of this routine, enter a non-hex-digit
ascii character, for example 'q'.
Example: M 100
100 A6
101 55
102 48 q
Z - disassemble
Z displays assembly mnemonics for the next 15 instructions in
memory starting at the current program counter, or, if an
address is entered, for the next 15 instructions starting at
that address. The display looks similar to a trace display
except no read/write data is shown and machine cycles are not
shown. Disassembly has no effect on simulation state.
H - halt
If simulation is in progress, it is stopped. The 'Running'
label on the first line changes to 'Halted'.
Q - quit
Leave sim_r3. The following appears on the prompt line:
Logfile closed - normal exit
Y - load symbol table. As stipulated above it is necessary to
specify the correct file with the symbol table (generated by
the FREEWARE assembler on the BBS) to prevent the program from
locking up.
Enter -
Just pressing 'Enter' does nothing but cause the line under
the prompt line to be redrawn. This is useful in case you
accidentally press "Escape" and DOS blows away the line.
III. Recompiling sim_r3
III. A. For the IBM-PC
III. A. 1. Using Microsoft C 5.0 or higher
This supplied code may be compiled without changes. The
supplied make file, makefile.mak, is for Polytron's POLYMAKE
to invoke the Microsoft C compiler. The makefile is written
in a manner which makes it very easy to convert for
Microsoft's make, which is supplied with Microsoft C. Only a
few lines need to be moved. Exact direction are in a comment
in makefile.mak.
III. A. 2.Using another compiler
Most of this program is "plain vanilla" C, and will port
unchanged. However, the functions which clear the screen and
position the text cursor are not portable. clearscreen and
settextposition call routines from Microsoft C 5.0's
graphics library. Most C compilers will supply library
routines for these functions, which may be substituted.
Delete_line uses the Microsoft C function "int86" to invoke
one of the DOS BIOS services. Again, most C compiles for the
PC will have some way to invoke the BIOS services, which may
be substituted.
If your compiler does NOT have cursor position and screen
functions, you may use ANSI.SYS to supply these functions.
ANSI.SYS is a file supplied with IBM DOS. It may be built
into the DOS of some clones. ANSI.SYS must be memory
resident. This requires the statement "DEVICE=ANSI.SYS" in
your config.sys file when you boot. Then, simply writing a
special sequence of characters to stdout will cause ANSI.SYS
to perform these functions. See the IBM DOS technical
reference for documentation on control codes for ANSI.SYS.
The code for using ANSI.SYS will look a lot like the code for
driving a VT-52 (a Digital Equipment Corp terminal), which is
included. However, the control codes are not the same:
ANSI.SYS uses DEC VT-100 control codes.
sim.h includes a #define for the type of graphics routines,
at the moment either MSC or VT52. I suggest you add another
#define and add your new C code right after each occurance of
"#ifdef VT52 ... #endif" in the routines settextposition and
clearscreen, both in sim_r3.c; and in the routine delete_line
in instr.c.
III. B. For non-IBM compatible machines
As long as your machine has an 80x25 character text display,
the only changes which need to be made are to support the
functions settextposition, clearscreen, and delete_line.
sim.h includes a #define for the type of graphics routines,
at the moment either MSC or VT52. I suggest you add another
#define and add your new C code right after each occurance of
"#ifdef VT52 ... #endif" in the routines settextposition and
clearscreen, both in sim_r3.c; and in the routine delete_line
in instr.c.
Note that if your computer emulates a DEC VT 52 terminal, or
if you will use this on a computer that actually drives a
terminal that can handle VT 52 control codes, then all you
have to do is uncomment "#define VT52" instead of "#define
MSC" in sim.h and recompile.
It is interesting to note that exactly the same parts of the
program need to be changed for a non-IBM compatible as for a
true IBM compatible but not Microsoft C 5.0 or higher. This
is because of the lack of standardization of even the most
rudimentary graphics functions; each compiler is different.
Perhaps X Windows will finally change this sad situation.
One further reflection on graphics standardization: I
mentioned above that sim_r3 was about 55,000 bytes when
compiled by Microsoft C 5.0. When compiled by Mark Williams
C for the Atari ST it is only about 36,000 bytes. This
difference is due mostly to the fact that support for the
needed graphics functions and VT52 emulation is part of the
ST's operating system, but requires routines from Microsoft C
5.0's graphics library in the IBM version. Consider the
amount of memory wasted in a multitasking environment if each
application includes the graphics library and ten or twenty
applications are running... This has nothing to do with
sim_r3, but it's one of my favorite subjects! My apologies.
I hope sim_r3 is useful to you.
--- Joe Schachner 8-July-1989
/* Amir Bernstein 27-November-1991, Happy Thanksgiving Joe in case you
get this before Thanksgiving */